home *** CD-ROM | disk | FTP | other *** search
/ PC Plus SuperCD (UK) 1998 August / PC Plus SuperCD 50a Issue 142 (CD142a) (August 1998).iso / trial / demon / TURNPIKE.1 / CLASSES.ZIP / JAVA / LANG / Thread.class (.txt) < prev    next >
Encoding:
Java Class File  |  1997-04-14  |  4.3 KB  |  258 lines

  1. package java.lang;
  2.  
  3. public class Thread implements Runnable {
  4.    private char[] name;
  5.    private int priority;
  6.    private Thread threadQ;
  7.    private int PrivateInfo;
  8.    private int eetop;
  9.    private boolean single_step;
  10.    private boolean daemon = false;
  11.    private boolean stillborn = false;
  12.    private Runnable target;
  13.    private boolean interruptRequested = false;
  14.    private static Thread activeThreadQ;
  15.    private ThreadGroup group;
  16.    private static int threadInitNumber;
  17.    public static final int MIN_PRIORITY = 1;
  18.    public static final int NORM_PRIORITY = 5;
  19.    public static final int MAX_PRIORITY = 10;
  20.  
  21.    private static synchronized int nextThreadNum() {
  22.       return threadInitNumber++;
  23.    }
  24.  
  25.    public static native Thread currentThread();
  26.  
  27.    public static native void yield();
  28.  
  29.    public static native void sleep(long var0) throws InterruptedException;
  30.  
  31.    public static void sleep(long var0, int var2) throws InterruptedException {
  32.       if (var2 > 500000) {
  33.          ++var0;
  34.       }
  35.  
  36.       sleep(var0);
  37.    }
  38.  
  39.    private void init(ThreadGroup var1, Runnable var2, String var3) {
  40.       Thread var4 = currentThread();
  41.       if (var1 == null) {
  42.          var1 = var4.group;
  43.       } else {
  44.          var1.checkAccess();
  45.       }
  46.  
  47.       this.group = var1;
  48.       this.daemon = var4.daemon;
  49.       this.priority = var4.priority;
  50.       this.name = var3.toCharArray();
  51.       this.target = var2;
  52.       this.setPriority0(this.priority);
  53.       var1.add(this);
  54.    }
  55.  
  56.    public Thread() {
  57.       this.init((ThreadGroup)null, (Runnable)null, "Thread-" + nextThreadNum());
  58.    }
  59.  
  60.    public Thread(Runnable var1) {
  61.       this.init((ThreadGroup)null, var1, "Thread-" + nextThreadNum());
  62.    }
  63.  
  64.    public Thread(ThreadGroup var1, Runnable var2) {
  65.       this.init(var1, var2, "Thread-" + nextThreadNum());
  66.    }
  67.  
  68.    public Thread(String var1) {
  69.       this.init((ThreadGroup)null, (Runnable)null, var1);
  70.    }
  71.  
  72.    public Thread(ThreadGroup var1, String var2) {
  73.       this.init(var1, (Runnable)null, var2);
  74.    }
  75.  
  76.    public Thread(Runnable var1, String var2) {
  77.       this.init((ThreadGroup)null, var1, var2);
  78.    }
  79.  
  80.    public Thread(ThreadGroup var1, Runnable var2, String var3) {
  81.       this.init(var1, var2, var3);
  82.    }
  83.  
  84.    public synchronized native void start();
  85.  
  86.    public void run() {
  87.       if (this.target != null) {
  88.          this.target.run();
  89.       }
  90.  
  91.    }
  92.  
  93.    private void exit() {
  94.       if (this.group != null) {
  95.          this.group.remove(this);
  96.          this.group = null;
  97.       }
  98.  
  99.    }
  100.  
  101.    public final void stop() {
  102.       this.stop(new ThreadDeath());
  103.    }
  104.  
  105.    public final synchronized void stop(Throwable var1) {
  106.       this.checkAccess();
  107.       this.stop0(var1);
  108.    }
  109.  
  110.    public void interrupt() {
  111.       this.interruptRequested = true;
  112.    }
  113.  
  114.    public static boolean interrupted() {
  115.       return currentThread().interruptRequested;
  116.    }
  117.  
  118.    public boolean isInterrupted() {
  119.       return this.interruptRequested;
  120.    }
  121.  
  122.    public void destroy() {
  123.       throw new NoSuchMethodError();
  124.    }
  125.  
  126.    public final native boolean isAlive();
  127.  
  128.    public final void suspend() {
  129.       this.checkAccess();
  130.       this.suspend0();
  131.    }
  132.  
  133.    public final void resume() {
  134.       this.checkAccess();
  135.       this.resume0();
  136.    }
  137.  
  138.    public final void setPriority(int var1) {
  139.       this.checkAccess();
  140.       if (var1 <= 10 && var1 >= 1) {
  141.          ThreadGroup var2 = this.group;
  142.          if (var1 > var2.maxPriority) {
  143.             var2 = this.group;
  144.             var1 = var2.maxPriority;
  145.          }
  146.  
  147.          this.setPriority0(this.priority = var1);
  148.       } else {
  149.          throw new IllegalArgumentException();
  150.       }
  151.    }
  152.  
  153.    public final int getPriority() {
  154.       return this.priority;
  155.    }
  156.  
  157.    public final void setName(String var1) {
  158.       this.checkAccess();
  159.       this.name = var1.toCharArray();
  160.    }
  161.  
  162.    public final String getName() {
  163.       char[] var1 = this.name;
  164.       return new String(var1);
  165.    }
  166.  
  167.    public final ThreadGroup getThreadGroup() {
  168.       return this.group;
  169.    }
  170.  
  171.    public static int activeCount() {
  172.       Thread var0 = currentThread();
  173.       return var0.group.activeCount();
  174.    }
  175.  
  176.    public static int enumerate(Thread[] var0) {
  177.       Thread var1 = currentThread();
  178.       return var1.group.enumerate(var0);
  179.    }
  180.  
  181.    public native int countStackFrames();
  182.  
  183.    public final synchronized void join(long var1) throws InterruptedException {
  184.       long var3 = System.currentTimeMillis();
  185.       long var5 = 0L;
  186.       if (var1 == 0L) {
  187.          while(this.isAlive()) {
  188.             this.wait(0L);
  189.          }
  190.  
  191.       } else {
  192.          while(this.isAlive()) {
  193.             long var7 = var1 - var5;
  194.             if (var7 <= 0L) {
  195.                break;
  196.             }
  197.  
  198.             this.wait(var7);
  199.             var5 = System.currentTimeMillis() - var3;
  200.          }
  201.  
  202.       }
  203.    }
  204.  
  205.    public final synchronized void join(long var1, int var3) throws InterruptedException {
  206.       if (var3 >= 500000 || var1 == 0L) {
  207.          ++var1;
  208.       }
  209.  
  210.       this.join(var1);
  211.    }
  212.  
  213.    public final void join() throws InterruptedException {
  214.       this.join(0L);
  215.    }
  216.  
  217.    public static void dumpStack() {
  218.       (new Exception("Stack trace")).printStackTrace();
  219.    }
  220.  
  221.    public final void setDaemon(boolean var1) {
  222.       this.checkAccess();
  223.       if (this.isAlive()) {
  224.          throw new IllegalThreadStateException();
  225.       } else {
  226.          this.daemon = var1;
  227.       }
  228.    }
  229.  
  230.    public final boolean isDaemon() {
  231.       return this.daemon;
  232.    }
  233.  
  234.    public void checkAccess() {
  235.       SecurityManager var1 = System.security;
  236.       if (var1 != null) {
  237.          var1.checkAccess(this);
  238.       }
  239.  
  240.    }
  241.  
  242.    public String toString() {
  243.       StringBuffer var10000 = (new StringBuffer()).append("Thread[");
  244.       char[] var1 = this.name;
  245.       var10000 = var10000.append(new String(var1)).append(",").append(this.priority).append(",");
  246.       ThreadGroup var2 = this.group;
  247.       return var10000.append(var2.name).append("]").toString();
  248.    }
  249.  
  250.    private native void setPriority0(int var1);
  251.  
  252.    private native void stop0(Object var1);
  253.  
  254.    private native void suspend0();
  255.  
  256.    private native void resume0();
  257. }
  258.